package com.itheima.service.impl;

import com.github.pagehelper.PageHelper;
import com.itheima.dao.RoleDao;
import com.itheima.domain.Permission;
import com.itheima.domain.Role;

import com.itheima.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleDao roleDao;

    @Override
    public List<Role> findAll(int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        return roleDao.findAll();
    }

    @Override
    public int save(Role role) {
        return roleDao.save(role);
    }

    @Override
    public Role findById(String id) {

        return roleDao.findById(id);
    }

    @Override
    public List<Permission> findRoleNotPermission(String id) {
        return roleDao.findRoleNotPermission(id);
    }

    @Override
    public int addPermissionToRole(String roleId, String[] ids) {
        int number=0;
        for (int i = 0; i <ids.length ; i++) {
            String id=ids[i];
            number = roleDao.addPermissionToRole(roleId,id);
        }
        return number;

    }
}
